package com.zyark.web.exception;


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ClassName: JsonDateSerializer  <br/>
 * Function:  <br/>
 * Reason:  <br/>
 * Date: 2017-06-09 15:28 <br/>
 *
 * @author Ku_ker
 * @version 1.0
 * @JDK 1.7
 */
public class JsonDateSerializer extends JsonSerializer<Date> {

    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) throws IOException,
            JsonProcessingException {
        String value = dateFormat.format(date);
        gen.writeString(value);
    }
}
